<template>
<div>
  <TopManu @handybjsdata='handybjsdata' @handcxyb='handcxyb'
  @fapiaodayin='fapiaodayin'></TopManu>

  <el-col :span="24" style="padding:40px">

          <infocrad :id='id'></infocrad>
            <viewTitle text="收费信息" style="font-size:20px;margin-bottom:10px" /> 
      <el-col :span="24" class='input_box'>
 
        <el-col :span="10" >
          <el-col :span="24" >
        
            <el-form
            label-position="right"
            label-width="80px"
            :model="orderinfo"
          > <el-col :span="10">
            <el-form-item label=" 费用:">
              <el-input size="mini" v-model="money" disabled></el-input>
             </el-form-item>
             </el-col>
             <el-col :span="10">
            <el-form-item label=" 残联余额:">
              <el-input size="mini" v-model="hosp_balance" disabled></el-input>
             </el-form-item>
             </el-col>
          <!-- <el-col :span="10">
             <el-form-item label="已使用:">
              <el-input size="mini" v-model="patientinfo.wallet.wallet_outcome" disabled></el-input>
             </el-form-item>
            </el-col> -->
         
            <!-- <el-col :span="10">
                   <el-form-item label="可用押金:">
              <el-input size="mini" v-model="patientinfo.wallet.wallet_money" disabled></el-input>
             </el-form-item></el-col> -->
             <!-- <el-col :span="10">
                   <el-form-item label="应收:">
              <el-input size="mini" v-model="yingshou" disabled></el-input>
             </el-form-item>
             </el-col> -->
                <!-- <el-col :span="10">
                   <el-form-item label="收银:">
              <el-input size="mini" v-model="moneysum" disabled></el-input>
             </el-form-item>
             </el-col> -->
              <!-- <el-col :span="10">
                   <el-form-item label="找零:">
              <el-input size="mini" v-model="form.zhaolin" disabled></el-input>
             </el-form-item>
             </el-col>
              <el-col :span="10">
                   <el-form-item label="抹零:">
              <el-input size="mini" v-model="form.moling" disabled></el-input>
             </el-form-item>
             </el-col> -->
              <!-- <el-col :span="10">
                   <el-form-item label="格式:">
              <el-select size="mini" v-model="form.region" placeholder="请选择格式">
      <el-option label="格式一" value="1"></el-option>
      <el-option label="格式二" value="2"></el-option>
    </el-select>
             </el-form-item>
             </el-col> -->
               <!-- <el-col :span="20">
                   <el-form-item label="">
    <el-checkbox-group v-model="form.type">
      <el-checkbox label="包干" name="type"></el-checkbox>
      <el-checkbox label="打印" name="type"></el-checkbox>
     
    </el-checkbox-group>
  </el-form-item>
             </el-col> -->
              
             </el-form>
            </el-col>
            
          <el-form
            label-position="right"
            label-width="80px"
            :model="orderinfo"
          >
            <el-col :span="24" >
            <el-col :span="11">
            <el-form-item label="微信">
              <el-input
              size="mini"
                v-model="orderinfo.payment[0].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
               </el-col>
                <el-col :span="11">
            <el-form-item label="支付宝">
              <el-input
              size="mini"
                v-model="orderinfo.payment[1].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
                   </el-col>
                <el-col :span="11">
            <el-form-item label="现金">
              <el-input
              size="mini"
                v-model="orderinfo.payment[2].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
                   </el-col>
                <el-col :span="11">
            <el-form-item label="银联">
              <el-input
              size="mini"
                v-model="orderinfo.payment[3].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
                   </el-col>
                <el-col :span="11">
            <el-form-item label="残联">
              <el-input
              size="mini"
                v-model="orderinfo.payment[6].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
                   </el-col>
                <!-- <el-col :span="11">
            <el-form-item label="医保">
              <el-input
              size="mini"
                v-model="orderinfo.payment[5].money"
                @change="moneysumfun"
              ></el-input>
            </el-form-item>
                   </el-col> -->
                <el-col :span="11">
            <el-form-item label="总计">
              <el-input size="mini" v-model="moneysum" disabled></el-input>
            </el-form-item>
                   </el-col>
                <el-col :span="11">
            <el-form-item label="大写">
              <el-input size="mini" v-model="damoneysum" disabled></el-input>
            </el-form-item>
               </el-col>
              </el-col>
          </el-form>
        
        </el-col>
       
        <el-col :span="14">
           <viewTitle text="费用信息" style="font-size:20px;margin-bottom:20px" /> 
           <jscostRecord :id='id'></jscostRecord>

        </el-col>
          <viewTitle text="医保结算信息" style="font-size:20px;margin-bottom:20px" /> 
        <el-col :span="24">
              <el-col :span="24">
            <el-form
            label-position="right"
             label-width="120px"
            :model="orderinfo"
          >
  <!-- <el-col :span="6">
      <el-form-item label="个人结算方式:" width='120px'>
                    <el-select
                      v-model="orderinfo.psn_setlway"
                      placeholder="个人结算方式"
                     
                       size="mini"
                    >
                      <el-option
                        v-for="(item, index) in jiesuan"
                        :key="index"
                        :label="item.name"
                        :value="item.id"
                        >{{ item.name }}</el-option
                      >
                    </el-select>
                  
                  </el-form-item>
                 </el-col>   
            <el-col :span="6">
            <el-form-item label="出院日期">
            
            <el-date-picker
      v-model="orderinfo.leave_time"
      type="date"
      placeholder="选择日期"
      format="yyyy 年 MM 月 dd 日"
      value-format="yyyy-MM-dd"
      size="mini">
    </el-date-picker>
            </el-form-item>
           
 </el-col> -->
              <el-col :span="6">
            <el-form-item label="医保支付">
              <el-input
              size="mini"
                v-model="fund_pay_sumamt"
                disabled
              ></el-input>
            </el-form-item>
                   </el-col>
         
                <el-col :span="6">
            <el-form-item label="个人负担总金额">
              <el-input
              size="mini"
                v-model="psn_part_amt"
                disabled
              ></el-input>
            </el-form-item>
                   </el-col>
                     <!-- <el-col :span="6">
            <el-form-item label="个人账户支出">
              <el-input
              size="mini"
                v-model="acct_pay"
                disabled
              ></el-input>
            </el-form-item>
                   </el-col>
                    -->
                <el-col :span="6">
            <el-form-item label="累计押金">
              <el-input size="mini" v-model="patientinfo.wallet.wallet_income" disabled></el-input>
            </el-form-item>
                   </el-col>
                <el-col :span="6">
            <el-form-item label="应付金额">
              <el-input size="mini" v-model="chuyuanfuk" disabled></el-input>
            </el-form-item>
               </el-col>
          </el-form>
           </el-col>
            <el-button type="success"  @click='jiezhang'>结算</el-button>
        
        </el-col>
        
      </el-col>
  </el-col> 
    <!-- 医保结算 -->
    <el-dialog :fullscreen='true' :close-on-click-modal='false' title="医保结算" :visible.sync="yibaojiesuan" width="80%">
      <yibaojisuan
        ref="yibaojiesuan"
        :user="patientinfo"
       @jine="jine(arguments)"
      >
      </yibaojisuan>
      <div slot="footer" class="dialog-footer">
        <el-button @click="yibaojiesuan = false">取 消</el-button>
        <el-button type="success" @click="handeyibaoSave">保 存</el-button>
      </div>
    </el-dialog>
    
  </div>
</template>

<script>

import ViewTitle from "@/forComponents/viewTitle";
import jscostRecord from "./jscostRecord.vue";
import {

  getdictIndex,

} from "@/api/register";
import {readHospitalMemberDetail,dischargeSettlement, getMemberCash,settCl } from "@/api/zhuyanre"
import infocrad from "./infocrad.vue";
import TopManu from "@/components/TopMenu";
import yibaojisuan from "./yibaojiesuan.vue";
import shouju from "./shouju.vue";
var that
export default {
  name:"costsRecord",
  props: ["patientinfo"],
  data(){
    return {
      tableData:[
      
      ],
      shoujulogdeposit:false,
      baoxiao:'',
      chuyuanfuk:'',
      jiesuan:[],
      tableTitle:[
       
         
      ],
      fund_pay_sumamt:'',
      psn_part_amt:'',
      acct_pay:'',
      money:0,
      yingshou:0,
      yibaojiesuan:false,
      form:{
          moling:0,
          zhaolin:0,
          region:'1',
          type:'',
      },
          orderinfo: {
        hospital_id: "",
        psn_setlway:'',
        leave_time: "",
        payment: [
          {
            payment: 1,
            money: 0
          },
          {
            payment: 2,
            money: 0
          },
          {
            payment: 3,
            money: 0
          },
          {
            payment: 4,
            money: 0
          },
          {
            payment: 5,
            money: 0
          },
          {
            payment: 6,
            money: 0
          },
           {
            payment: 7,
            money: 0
          }
        ]
      },
      moneysum:'',
      damoneysum:'',
      //残联余额
      hosp_balance:'',
      //医疗费用
      medfee_sumamt:'',
      id:'',
      uid:''
    }
  },
  mounted(){
    that=this 
    this.id = this.$route.query.id;
     this.uid = this.$route.query.uid;
    this.getdiet_list()
       this.getMemberCash()
    this.readHospitalMemberDetail(this.id)
 
  },
  methods:{
     getMemberCash(){
       var data={
         member_id:this.uid,
         hospital_id:this.id
       }
         getMemberCash(data).then(res=>{
           console.log(res)
             this.hosp_balance=res.data.disable.hosp_balance
      //医疗费用
      this.medfee_sumamt=res.data.setl_info.medfee_sumamt
      this.psn_part_amt=res.data.setl_info.psn_part_amt
this.fund_pay_sumamt=res.data.setl_info.fund_pay_sumamt
         })
     },
      getdiet_list() {
      getdictIndex({ group_id: "63" })
        .then(arr => {
          let data = arr.data;

          data.forEach((item, key) => {
            if(item.id==63){
               
             that.jiesuan=item.items;
            }
            

           
          });
        })
        .catch(e => {});

    },
    handcxyb(){
          this.$confirm('是否撤销结算?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
                  settCl({id:this.id}).then(res=>{
                  if (res.code=200) {
                    this.$message({
                    message: "办理成功",
                    type: "success"
                  });
                  }
          })
         
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });          
        });

    },
    handeyibaoSave(){
        
        this.$refs.yibaojiesuan.jine()
    },
    jine(arr){
        this.psn_part_amt=arr[0].psn_part_amt
        this.fund_pay_sumamt=arr[0].fund_pay_sumamt
        this.acct_pay=arr[0].acct_pay
        this.yingshou=arr[0].psn_part_amta
    },
 
       readHospitalMemberDetail(id){
        readHospitalMemberDetail({id:id}).then(res=>{
            console.log(res)
             var objdata={}
             this.money=res.data.money
        Object.assign(objdata, res.data.masterInfo, res.data.nodeInfo,res.data.member);
        this.patientinfo=objdata
        this.patientinfo.room_info=objdata.room_name.split('/')
        
        })
      },
    handybjsdata(){
        this.yibaojiesuan=true
    },
// jine(arr){
//   var fei=parseInt(this.money)
//   var fei2=parseInt(arr[0])
//   if (fei>fei2) {
//      this.yingshou =parseInt(this.patientinfo.wallet.wallet_income)-(fei-fei2 )  
//   }else{
//      this.yingshou =parseInt(this.patientinfo.wallet.wallet_income)-(fei2-fei )  
//   }

// },
        jiezhang() {
       this.orderinfo.hospital_id=this.patientinfo.id
      // if(this.isCollapse==1){
            dischargeSettlement(this.orderinfo).then(res => {
        if (res.code == 200) {
        
          this.$message({
            message: "结账成功",
            type: "success"
          });
        }
      });
    

    },
   
       //押金总和
    moneysumfun() {
      var arr = that.orderinfo.payment;
      var num = 0;
      var num1 = that.NumberAdd(num, parseFloat(arr[0].money));
      var num2 = that.NumberAdd(num1, parseFloat(arr[1].money));
      var num3 = that.NumberAdd(num2, parseFloat(arr[2].money));
      var num4 = that.NumberAdd(num3, parseFloat(arr[3].money));
      var num5 = that.NumberAdd(num4, parseFloat(arr[4].money));
      that.moneysum = that.NumberAdd(num5, parseFloat(arr[5].money));
      that.damoneysum = that.AmountLtoU(that.moneysum);
    },
    AmountLtoU(num) {
      ///<summery>小写金额转化大写金额</summery>
      ///<param name=num type=number>金额</param>
      if (isNaN(num)) return "";
      var strPrefix = "";
      if (num < 0) strPrefix = "(负)";
      num = Math.abs(num);
      if (num >= 1000000000000) return "无效数值！";
      var strOutput = "";
      var strUnit = "仟佰拾亿仟佰拾万仟佰拾元角分";
      var strCapDgt = "零壹贰叁肆伍陆柒捌玖";
      num += "00";
      var intPos = num.indexOf(".");
      if (intPos >= 0) {
        num = num.substring(0, intPos) + num.substr(intPos + 1, 2);
      }
      strUnit = strUnit.substr(strUnit.length - num.length);
      for (var i = 0; i < num.length; i++) {
        strOutput +=
          strCapDgt.substr(num.substr(i, 1), 1) + strUnit.substr(i, 1);
      }
      return (
        strPrefix +
        strOutput
          .replace(/零角零分$/, "整")
          .replace(/零[仟佰拾]/g, "零")
          .replace(/零{2,}/g, "零")
          .replace(/零([亿|万])/g, "$1")
          .replace(/零+元/, "元")
          .replace(/亿零{0,3}万/, "亿")
          .replace(/^元/, "零元")
      );
    },
  },
  components:{

    ViewTitle,
    jscostRecord,
    
    TopManu,

    infocrad,
   
    yibaojisuan,
    shouju
  
  }
}
</script>

<style>
.input_box>>>.el-form-item{
  margin-bottom: 0px !important;
}
</style>